package com.supergo.manager.controller;

import com.supergo.manager.feign.ApiBrandFeign;
import com.supergo.http.HttpResult;
import com.supergo.pojo.Brand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Classname BrandController
 * @Description TODO
 * @Date 2020/10/26 14:54
 * @Created by ccc-j
 * @email ccc-ju@outlook.com
 */
@RestController
@RequestMapping("/brand")
@Api(value = "品牌控制器", protocols = "http", description = "品牌控制器")
public class BrandController {

    @Autowired
    private ApiBrandFeign apiBrandFeign;

    @ApiOperation(value = "根据id查询品牌", notes = "查询品牌详情")
    @RequestMapping(value = "/{brandId}", method = RequestMethod.GET)
    public HttpResult getBrandById(@PathVariable Long brandId){
        Brand brand = apiBrandFeign.getBrandByid(brandId);
        return HttpResult.ok(brand);
    }

    @ApiOperation(value = "品牌分页查询", notes = "接收分页参数与查询信息（page, rows）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "第几页", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示行数", required = true, dataType = "int")
    })
    @PostMapping("/query/{page}/{size}")
    public HttpResult getBrandPage(@RequestBody Brand brand,
                                   @PathVariable Integer page,
                                   @PathVariable Integer size){
        return apiBrandFeign.findPage(brand, page, size);
    }


}
